package com.li.wallet;

import android.app.Activity;
import android.os.Bundle;
import android.os.Vibrator;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;
import android.widget.Toast;

public class WalletManagerActivity extends Activity {

	private Vibrator vibrator;
	private EditText etWait1, etWait2, etRun1, etRun2;
	long l1, l2, l3, l4;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		vibrator = (Vibrator) this.getSystemService(VIBRATOR_SERVICE);

		etWait1 = (EditText) findViewById(R.id.wait1);
		etWait2 = (EditText) findViewById(R.id.wait2);
		etRun1 = (EditText) findViewById(R.id.run1);
		etRun2 = (EditText) findViewById(R.id.run2);

		Log.e("lmf", etWait1.getText().toString());
	}

	public boolean onCreateOptionsMenu(Menu menu) {
		// TODO Auto-generated method stub
		menu.add(0, 1, 1, "运行");
		menu.add(0, 2, 2, "停止");
		return super.onCreateOptionsMenu(menu);
	}

	public boolean onOptionsItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		if (item.getItemId() == 1) {

			if (etWait1.getText().toString().equals("")) {
				l1 = Long.parseLong(etWait1.getHint().toString());
			} else {
				l1 = Long.parseLong(etWait1.getText().toString());
			}
			if (etRun1.getText().toString().equals("")) {
				l2 = Long.parseLong(etRun1.getHint().toString());
			} else {
				l2 = Long.parseLong(etRun1.getText().toString());
			}
			if (etWait2.getText().toString().equals("")) {
				l3 = Long.parseLong(etWait2.getHint().toString());
			} else {
				l3 = Long.parseLong(etWait2.getText().toString());
			}
			if (etRun2.getText().toString().equals("")) {
				l4 = Long.parseLong(etRun2.getHint().toString());
			} else {
				l4 = Long.parseLong(etRun2.getText().toString());
			}

			vibrator.vibrate(new long[] { l1, l2, l3, l4 }, 0);

		} else if (item.getItemId() == 2) {

			vibrator.cancel();
		}
		return true;
	}

}